package cn.maihe.elg.operation.supports.electronicseal.jd.service.impl;

import cn.maihe.elg.operation.supports.electronicseal.jd.dto.req.DownloadSignatureFileReqDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.dto.req.FileSignatureReqDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.dto.req.GenerateSignatureFileReqDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.dto.req.UploadAssembleOfdFileReqDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.dto.req.UploadPendingSignatureFileReqDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.dto.resp.FileSignatureRespDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.dto.resp.GenerateSignatureFileRespDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.dto.resp.JDOfdSignatureBaseDTO;
import cn.maihe.elg.operation.supports.electronicseal.jd.service.JDSignatureService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.nio.file.Path;

@Slf4j
@Service
public class JDSignatureServiceImpl extends JDSignatureService {
    @Override
    public JDOfdSignatureBaseDTO uploadPendingSignatureFile(String url,UploadPendingSignatureFileReqDTO reqDTO, MultiValueMap<String, Object> body) {
        log.info("uploadPendingSignatureFile url:{}; reqDTO:{}",url,JSON.toJSONString(reqDTO));
        JDOfdSignatureBaseDTO respDTO = doRequestFormFata(url, reqDTO, body,JDOfdSignatureBaseDTO.class);
        log.info("uploadPendingSignatureFile respDTO:{}",JSON.toJSONString(respDTO));
        return respDTO;
    }

    @Override
    public JDOfdSignatureBaseDTO uploadAssembleOfdFile(String url,UploadAssembleOfdFileReqDTO reqDTO, MultiValueMap<String, Object> body) {
        log.info("uploadAssembleOFDFile url:{}; reqDTO:{}",url,JSON.toJSONString(reqDTO));
        JDOfdSignatureBaseDTO respDTO = doRequestFormFata(url, reqDTO, body ,JDOfdSignatureBaseDTO.class);
        log.info("uploadAssembleOFDFile respDTO:{}",JSON.toJSONString(respDTO));
        return respDTO;
    }

    @Override
    public FileSignatureRespDTO fileSignature(String url,FileSignatureReqDTO reqDTO, MultiValueMap<String, Object> body) {
        log.info("fileSignature url:{}; reqDTO:{}",url,JSON.toJSONString(reqDTO));
        FileSignatureRespDTO respDTO = doRequest(url, reqDTO, body, FileSignatureRespDTO.class);
        log.info("fileSignature respDTO:{}",JSON.toJSONString(respDTO));
        return respDTO;
    }

    @Override
    public GenerateSignatureFileRespDTO generateSignatureFile(String url,GenerateSignatureFileReqDTO reqDTO, MultiValueMap<String, Object> body) {
        log.info("generateSignatureFile url:{}; reqDTO:{}",url,JSON.toJSONString(reqDTO));
        GenerateSignatureFileRespDTO respDTO = doRequest(url, reqDTO,body, GenerateSignatureFileRespDTO.class);
        log.info("generateSignatureFile respDTO:{}",JSON.toJSONString(respDTO));
        return respDTO;
    }

    @Override
    public Path downloadSignatureFile(String url, DownloadSignatureFileReqDTO reqDTO, String savePath, MultiValueMap<String, Object> body) {
        log.info("downloadSignatureFile url:{}; reqDTO:{},savePath:{};",url,JSON.toJSONString(reqDTO),savePath);
        return downloadEnterpriseFile(url, reqDTO, body, savePath);
    }
}
